home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 2D / CopyBits vs. CopyMask / Sample.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  9.6 KB  |  227 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Sample.h
  3.  
  4.     Contains:    Sample is an example application that demonstrates how to
  5.                 initialize the commonly used toolbox managers, operate 
  6.                 successfully under MultiFinder, handle desk accessories, 
  7.                 and create, grow, and zoom windows.
  8.     
  9.                 It does not by any means demonstrate all the techniques 
  10.                 you need for a large application. In particular, Sample 
  11.                 does not cover exception handling, multiple windows/documents, 
  12.                 sophisticated memory management, printing, or undo. All of 
  13.                 these are vital parts of a normal full-sized application.
  14.     
  15.                 This application is an example of the form of a Macintosh 
  16.                 application; it is NOT a template. It is NOT intended to be 
  17.                 used as a foundation for the next world-class, best-selling, 
  18.                 600K application. A stick figure drawing of the human body may 
  19.                 be a good example of the form for a painting, but that does not 
  20.                 mean it should be used as the basis for the next Mona Lisa.
  21.     
  22.                 We recommend that you review this program or TESample before 
  23.                 beginning a new application.
  24.  
  25.     Written by:     
  26.  
  27.     Copyright:    Copyright © 1989-1999 by Apple Computer, Inc., All Rights Reserved.
  28.  
  29.                 You may incorporate this Apple sample source code into your program(s) without
  30.                 restriction. This Apple sample source code has been provided "AS IS" and the
  31.                 responsibility for its operation is yours. You are not permitted to redistribute
  32.                 this Apple sample source code as "Apple sample source code" after having made
  33.                 changes. If you're going to re-distribute the source, we require that you make
  34.                 it clear in the source that the code was descended from Apple sample source
  35.                 code, but that you've made changes.
  36.  
  37.     Change History (most recent first):
  38.                 7/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  39.                 
  40.  
  41. */
  42. #include <Dialogs.h>
  43. #include <Fonts.h>
  44. /* In MPW 3.0 and THINK C we can use actual prototypes for parameter type checking. */
  45. /* Function prototypes for all functions in this program. */
  46.  
  47. #ifndef rez
  48. void EventLoop( void );
  49. void HandleNormalEvent(EventRecord *event);
  50. void HandleDialogEvent(EventRecord *event);
  51. void AdjustCursor( Point mouse, RgnHandle region );
  52. void GetGlobalMouse( Point *mouse );
  53. void DoUpdate( WindowPtr window );
  54. void DoActivate( WindowPtr window, Boolean becomingActive );
  55. void DoContentClick( WindowPtr window );
  56. void DrawWindow( WindowPtr window );
  57. void AdjustMenus( void );
  58. void DoMenuCommand( long menuResult );
  59. void SetLight( WindowPtr window, Boolean newStopped );
  60. Boolean DoCloseWindow( WindowPtr window );
  61. void Terminate( void );
  62. void ForceEnvirons( void );
  63. Boolean IsAppWindow( WindowPtr window );
  64. Boolean IsDAWindow( WindowPtr window );
  65. void AlertUser( void );
  66. void Initialize( void );
  67. Boolean GoGetRect( short rectID, Rect *theRect );
  68. Boolean TrapAvailable( short tNumber, TrapType tType );
  69.  
  70. void LetTheGameBegin(DialogPtr srcDialogP);
  71. #endif
  72.  
  73. /*    These #defines correspond to values defined in the Pascal source code.
  74.     Sample.c and Sample.r include this file. */
  75.  
  76. /*    Determining an application's minimum size to request from MultiFinder depends
  77.     on many things, each of which can be unique to an application's function,
  78.     the anticipated environment, the developer's attitude of what constitutes
  79.     reasonable functionality and performance, etc. Here is a list of some things to
  80.     consider when determining the minimum size (and preferred size) for your
  81.     application. The list is pretty much in order of importance, but by no means
  82.     complete.
  83.     
  84.     1.    What is the minimum size needed to give almost 100 percent assurance
  85.         that the application won't crash because it ran out of memory? This
  86.         includes not only things that you do have direct control over such as
  87.         checking for NIL handles and pointers, but also things that some
  88.         feel are not so much under their control such as QuickDraw and the
  89.         Segment Loader.
  90.         
  91.     2.    What kind of performance can a user expect from the application when
  92.         it is running in the minimum memory configuration? Performance includes
  93.         not only speed in handling data, but also things like how many documents
  94.         can be opened, etc.
  95.         
  96.     3.    What are the typical sizes of scraps [is a boy dog] that a user might
  97.         wish to work with when lauching or switching to your application? If
  98.         the amount of memory is too small, the scrap may get lost [will have
  99.         to be shot]. This can be quite frustrating to the user.
  100.         
  101.     4.    The previous items have concentrated on topics that tend to cause an
  102.         increase in the minimum size to request from MultiFinder. On the flip
  103.         side, however, should be the consideration of what environments the
  104.         application may be running in. There may be a high probability that
  105.         many users with relatively small memory configurations will want to
  106.         avail themselves of your application. Or, many users might want to use it
  107.         while several other, possibly related/complementary applications are
  108.         running. If that is the case, it would be helpful to have a fairly
  109.         small minimum size.
  110.     
  111.     So, what did we decide on Sample? First, Sample has little risk of
  112.     running out of memory once it starts. Second, performance isn't much
  113.     of an issue since it doesn't do much and multiple windows are not
  114.     allowed. Third, there are no edit operations in Sample itself, so we
  115.     just want to provide enough space for a reasonable scrap to survive
  116.     between desk accessory launches. Lastly, Sample should intrude as little
  117.     as possible, so the effort should be towards making it as small as possible.
  118.     We looked at some heap dumps while the application was running under
  119.     various partition sizes. With a size of 23K, there was approximately
  120.     8-9K free, which is a good 'slop' factor in an application like this
  121.     which doesn't do much, but where we'd still like the scrap to survive
  122.     most of the time. */
  123.  
  124. #define kMinSize    23                /* application's minimum size (in K) */
  125.  
  126. /*    We made the preferred size bigger than the minimum size by 12K, so that
  127.     there would be even more room for the scrap, FKEYs, etc. */
  128.  
  129. #define kPrefSize    35                /* application's preferred size (in K) */
  130.  
  131. #define    rMenuBar    128                /* application's menu bar */
  132. #define    rAboutAlert    128                /* about alert */
  133. #define    rUserAlert    129                /* error user alert */
  134. #define    rWindow        1000            /* application's window */
  135. #define rStopRect    128                /* rectangle for Stop light */
  136. #define rGoRect        129                /* rectangle for Go light */
  137.  
  138. /* kSysEnvironsVersion is passed to SysEnvirons to tell it which version of the
  139.    SysEnvRec we understand. */
  140.  
  141. #define    kSysEnvironsVersion        1
  142.  
  143. /* kOSEvent is the event number of the suspend/resume and mouse-moved events sent
  144.    by MultiFinder. Once we determine that an event is an osEvent, we look at the
  145.    high byte of the message sent to determine which kind it is. To differentiate
  146.    suspend and resume events we check the resumeMask bit. */
  147.  
  148. #define    kOSEvent                15    /* event used by MultiFinder */
  149. #define    kSuspendResumeMessage    1        /* high byte of suspend/resume event message */
  150. #define    kResumeMask                1        /* bit of message field for resume vs. suspend */
  151. #define    kMouseMovedMessage        0xFA    /* high byte of mouse-moved event message */
  152. #define    kNoEvents                0        /* no events mask */
  153.  
  154. /* The following constants are used to identify menus and their items. The menu IDs
  155.    have an "m" prefix and the item numbers within each menu have an "i" prefix. */
  156.  
  157. #define    mApple                    128        /* Apple menu */
  158. #define    iAbout                    1
  159.  
  160. #define    mFile                    129        /* File menu */
  161. #define    iNew                    1
  162. #define    iClose                    4
  163. #define    iQuit                    12
  164.  
  165. #define    mEdit                    130        /* Edit menu */
  166. #define    iUndo                    1
  167. #define    iCut                    3
  168. #define    iCopy                    4
  169. #define    iPaste                    5
  170. #define    iClear                    6
  171.  
  172. #define    mLight                    131        /* Light menu */
  173. #define    iStop                    1
  174. #define    iGo                        2
  175.  
  176.  
  177. // dialog item constants
  178. #define kReadySetGoButton        17
  179.  
  180. /*    1.01 - kTopLeft - This is for positioning the Disk Initialization dialogs. */
  181.  
  182. #define kDITop                    0x0050
  183. #define kDILeft                    0x0070
  184.  
  185. /*    1.01 - kMinHeap - This is the minimum result from the following
  186.     equation:
  187.         
  188.         ORD(GetApplLimit) - ORD(ApplicZone)
  189.         
  190.     for the application to run. It will insure that enough memory will
  191.     be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  192.     application, and still give the application some 'breathing room'.
  193.     To derive this number, we ran under a MultiFinder partition that was
  194.     our requested minimum size, as given in the 'SIZE' resource. */
  195.      
  196. #define kMinHeap                21 * 1024
  197.     
  198. /*    1.01 - kMinSpace - This is the minimum result from PurgeSpace, when called
  199.     at initialization time, for the application to run. This number acts
  200.     as a double-check to insure that there really is enough memory for the
  201.     application to run, including what has been taken up already by
  202.     pre-loaded resources, the scrap, code, and other sundry memory blocks. */
  203.      
  204. #define kMinSpace                8 * 1024
  205.  
  206. /* kExtremeNeg and kExtremePos are used to set up wide open rectangles and regions. */
  207.  
  208. #define kExtremeNeg                -32768
  209. #define kExtremePos                32767 - 1 /* required to address an old region bug */
  210.  
  211. /* these #defines are used to set enable/disable flags of a menu */
  212.  
  213. #define AllItems    0b1111111111111111111111111111111    /* 31 flags */
  214. #define NoItems        0b0000000000000000000000000000000
  215. #define MenuItem1    0b0000000000000000000000000000001
  216. #define MenuItem2    0b0000000000000000000000000000010
  217. #define MenuItem3    0b0000000000000000000000000000100
  218. #define MenuItem4    0b0000000000000000000000000001000
  219. #define MenuItem5    0b0000000000000000000000000010000
  220. #define MenuItem6    0b0000000000000000000000000100000
  221. #define MenuItem7    0b0000000000000000000000001000000
  222. #define MenuItem8    0b0000000000000000000000010000000
  223. #define MenuItem9    0b0000000000000000000000100000000
  224. #define MenuItem10    0b0000000000000000000001000000000
  225. #define MenuItem11    0b0000000000000000000010000000000
  226. #define MenuItem12    0b0000000000000000000100000000000
  227.